<%@ page language="java" import="java.util.*" import="java.sql.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="blog.anchen8.net" />
<title>毕业生，你的选择</title>
<link rel="stylesheet" type="text/css" href="../css/personal.css" />
<script src="../js/jQuery1.82.js" type="text/javascript"></script>
<script type="text/javascript">
        function createMain(){
            var _scrollWidth=Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
            var _scrollHeight=Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
                document.getElementById("main").style.left=(_scrollWidth-950)/2+"px";
               // document.getElementById("m").style.height=_scrollHeight+"px";
        }
        function naviover(val){
            document.getElementById(val).style.backgroundColor="#E1DACF";
        }
        function naviout(val){
            document.getElementById(val).style.backgroundColor="#C5C5C5";
        }
        $(document).ready(function() {
			/*	2nd example	*/
			
			$("#menu2 li a").wrapInner( '<span class="out"></span>' );
			
			$("#menu2 li a").each(function() {
				$( '<span class="over">' +  $(this).text() + '</span>' ).appendTo( this );
			});

			$("#menu2 li a").hover(function() {
				$(".out",	this).stop().animate({'top':	'45px'},	200); // move down - hide
				$(".over",	this).stop().animate({'top':	'0px'},		200); // move down - show

			}, function() {
				$(".out",	this).stop().animate({'top':	'0px'},		200); // move up - show
				$(".over",	this).stop().animate({'top':	'-45px'},	200); // move up - hide
			});

		});
    </script>
</head>
<body class="body">
	<jsp:useBean id="m_pages" scope="page"
		class="com.tzq.JAVABEAN.ShowBlog"></jsp:useBean>
	<jsp:useBean id="sql" scope="page" class="com.tzq.JAVABEAN.ConnectDB" />
	<%
	
   String userid = request.getParameter("userid");
if(userid==null){%>
	<jsp:forward page="/Public/PublicMainPage.jsp"></jsp:forward>
	<%}
String Sessionid = null;

if(session.getAttribute("pid")!=null){
	   Sessionid = session.getAttribute("pid").toString();
}
boolean flag = userid.equals(Sessionid);    //判断是否是本用户访问此页面
int curPages = m_pages.current_Pages(m_pages.strPage(request,"page"));
m_pages.setPage_record(12);//设置每页显示10条
%>

<%
int resultconts=0;
String usernameString="";
ResultSet rsName = sql.executeQuery("select UserName from Userinfo where UserID="+userid+"");
if(rsName.next()){
	usernameString = rsName.getString("UserName");
}

ResultSet rs_count=sql.executeQuery("select UserName,count(*) as t from Blog,Userinfo where AuthorID="+userid+" and AuthorID=UserID group by UserName");//传递进数据库处理的javabean
if(rs_count.next()){
	resultconts=rs_count.getInt("t");//取得总的数据数
}

int totalPages = m_pages.getTotal_Pages(resultconts);//取出总页数
ResultSet rs=m_pages.getPageSet(sql.executeQuery("select * from Blog where AuthorID="+userid+""),curPages);//获取指针的结果集参数是(结果集，页数)
String[] nameArray=new String[resultconts];
String[] dateArray=new String[resultconts];
String[] clickArray=new String[resultconts];
String[] authorArray=new String[resultconts];
int num=0;
while (rs.next()){ 
	nameArray[num] = rs.getString("BlogName"); 
	dateArray[num] =rs.getString("LastChangeTime");
	clickArray[num] = rs.getString("ClickTimes");
	num=num+1;
	if(num>11){
	    break;
	}
}
%>
	<div class="main" id="main">
		<span class="title"><%=usernameString %>的空间</span>
		<div id="menu2" class="menu">
			<ul>
				<li id="info"><a href="/Bys-Website/PersonMainPage.jsp?userID=<%=userid%>">个人信息</a></li>
				<li id="video"><a href="/Bys-Website/PersonVideo/MyVideo.jsp?userid=<%=userid %>">个人视频</a></li>
				<li id="photo"><a href="/Bys-Website/PersonImage/MyImage.jsp?userid=<%=userid%>">个人相册</a></li>
				<li id="blog"><a href="/Bys-Website/PersonBlog/MyBlog.jsp?userid=<%=userid%>">个人博客</a></li>
				<li><a href="javascript:;">Contacts</a></li>
			</ul>
		</div>
		<div id="blogde">
			<div class="blogtitle">
				&nbsp;博客列表
				<%if(flag){%>
				<form>
					<input type="button" value="写博客"
						onclick="window.open('WriteBlog.jsp')" />
				</form>
				<%}%>
			</div>
			<div class="bloglist">
				<div class="blogname">
					<ul>
					<%for(int i=0;i<num;i++){%>
							<li><a href="ShowBlogContext.jsp?blogname=<%=nameArray[i] %>&authorid=<%=userid%>"><%=nameArray[i]%></a></li>
					<%}%>
					</ul>
				</div>
				<div class="date_click">
					<ul>
					<%for(int i=0;i<num;i++){%>
							<li><%=dateArray[i]%>(<%=clickArray[i] %>)</li>
					<%}%>
					</ul>
				</div>
				<%if(flag){ %>
				<div class="blogedit">
					<ul>
						<%for(int i=0;i<num;i++){%>
							<li><a href="DeleteServlet?method=0&blogname=<%=nameArray[i]%>">删除</a> <a href="ModifyBlog.jsp?blogname=<%=nameArray[i] %>&authorid=<%=userid%>">编辑</a></li>
						<%}%>
					</ul>
				</div>
				<%} %>
				<div class="pgswitch">
					<div class="pgpre2">
						<%if(curPages>1){%><a href="MyBlog.jsp?page=<%=curPages-1%>&userid=<%=userid%>">上一页</a>
						<%}%>
					</div>
					<div class="pgnext2">
						<%if(curPages<totalPages){%><a href="MyBlog.jsp?page=<%=curPages+1%>&userid=<%=userid%>">下一页</a>
						<%}%>
					</div>
				</div>
			</div>
			<div class="blogshow"></div>
		</div>
	</div>
	<script>    
        createMain();
    </script>
	<div class="topbar">
		<div class="logo">
			<a href="/Bys-Website/Public/home.jsp">
	           	<img src="/Bys-Website/SourceImageFile/toplogo.jpg"/>
			</a>
		</div>
		<div class="navi">
			<ul class="naviul">
				<li><a href="/Bys-Website/Public/Video.jsp" class="outli">视频</a></li>
				<li><a href="/Bys-Website/Public/Photo.jsp" class="outli">相册</a></li>
				<li><a href="/Bys-Website/Public/Blog.jsp" class="inli">博客</a></li>
			</ul>
		</div>
		<div class="loginfo">
			<ul class="loginfoul">
				<%if(session.getAttribute("pid")==null){%>
				<li><a href="/Bys-Website/Log_in.jsp">登录</a></li>
				<li><a href="/Bys-Website/Regist.jsp">注册</a></li>
			<%}else{%>
				<li><a href="../PersonMainPage.jsp?userID=<%=Sessionid  %>"><%=session.getAttribute("username").toString()%></a></li>
				<li><a href="../LoginServlet?method=1">退出</a></li>
			<%}%>
			</ul>
		</div>
	</div>
	<%sql.closeConnection(); %>
</body>
</html>